package cn.kgc.layui.servlet;

import cn.kgc.layui.service.StudentService;
import cn.kgc.layui.service.impl.StudentServiceImpl;
import cn.kgc.layui.util.LayUiResult;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateUser")
public class UserUpdateServlet extends HttpServlet {
    private static StudentService studentService = new StudentServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 获取前端传递的参数
        req.setCharacterEncoding("utf-8");
        String stuName= req.getParameter("stuName");
        String tel= req.getParameter("tel");
        String stuNo= req.getParameter("stuNo");
        String id= req.getParameter("id");
        int result=studentService.update(stuName,tel,stuNo,id);
        LayUiResult layUiResult;
        if(result>0){
            layUiResult=LayUiResult.builder().code(200).msg("修改成功").build();
        }else {
            layUiResult=LayUiResult.builder().code(500).msg("修改失败").build();
        }
        String strResult = JSON.toJSONString(layUiResult);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(strResult);
    }

}
